package com.example.rabbitmqspringboot.demos.web.conf;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: StudDeadBindsConf
 * @Description:
 * @Date 2024/04/11 10:06
 * @Author songshaoqiu
 **/
@Configuration
public class StudDeadBindsConf {


    @Bean
    public Queue normalStudQueue(){
        Map<String, Object> map = new HashMap<>();
        //设置队列最大长度
        map.put("x-max-length",2);
        //设置死信队列交换机
        map.put("x-dead-letter-exchange","studExchange");
        //设置死信队列路由key
        map.put("x-dead-letter-routing-key","dead-routing-key");

        return new Queue("normal-stud-queue", true,false,false,map);
    }

    @Bean
    public Exchange studExchange(){
        return new TopicExchange("studExchange",true,false,null);
    }


    @Bean
    public Binding normalStudBind(){

        return new Binding("normal-stud-queue",
                Binding.DestinationType.QUEUE ,
                "studExchange",
                "publish-stud-msg", null);
    }
    //创建死信队列
    @Bean
    public Queue StudDeadQueue(){
        return new Queue("stud-nAck-queue", true,false,false,null);
    }
    @Bean
    public Binding deadQueueBing(){
        return new Binding("stud-nAck-queue",
                Binding.DestinationType.QUEUE,
                "studExchange",
                "dead-routing-key",
                null);
    }



}
